<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<link rel="stylesheet" type="text/css" href="/static/component/laytp/module/cityPicker/city-picker.css">

<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span>开竣工</span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container">

        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">项目名称</label>
                        <div class="layui-input-block">
                            <input type="text" id="name" placeholder="请输入" autocomplete="off" disabled class="layui-input disabled">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">当前状态</label>
                        <div class="layui-input-block">
                            <input type="text" id="state_name" placeholder="请输入" autocomplete="off" disabled class="layui-input disabled">
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>变更为</label>
                        <div class="layui-input-block">
                            <select id="state" name="state" lay-filter="state" ></select>
                            <p class="error" id="state_error" style="margin: 0;"></p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide" id="actualdtDiv">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>实际开工日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="actualdt" id="actualdt" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide" id="filishdtDiv">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>竣工验收日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="filishdt" id="filishdt" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                </div>
            </div>

        </div>

    </div>
</form>
<script>
    var param_id = getQueryVariable('id') || 0;

    $("#commentForm").validate({
        rules: {
            actualdt: {required: true},
            filishdt: {required: true},
        },
        messages:{
            actualdt: {required: "请选择"},
            filishdt: {required: "请选择"},
        }
    });

    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_engin_kaijun, data:{id:param_id}}).done(function(res){
            if (res.code === 2000) {
                var data = res.data.data;
                $("#name").val(data.name);
                $("#state_name").val(data.state_name);
                $("#actualdt").val(data.actualdt);
                $("#filishdt").val(data.filishdt);


                var state_str = '<option value="">请选择</option>';
                var state = res.data.state;
                for (var key in state){
                    state_str += '<option value="'+key+'">'+state[key]+'</option>';
                }
                $("#state").html(state_str);

                render_from();
            }
        });

        form.on('select(state)', function(data){
            if(data.value == ''){
                $('#state_error').show().text('请选择');
                $('#state_error').parent().find('input').addClass('select_error');
            }else{
                $('#state_error').hide();
                $('#state_error').parent().find('input').removeClass('select_error');
            }

            if(data.value == 3){
                $("#actualdtDiv").removeClass('layui-hide');
                $("#filishdtDiv").addClass('layui-hide');
            }else if(data.value == 6){
                $("#actualdtDiv").removeClass('layui-hide');
                $("#filishdtDiv").removeClass('layui-hide');
            }else{
                $("#actualdtDiv").addClass('layui-hide');
                $("#filishdtDiv").addClass('layui-hide');
            }

        });

        form.on('submit(add)', function(data){
            var validRes = $("#commentForm").valid();
            if(data.field.state == ''){
                $('#state_error').show().text('请选择');
                $('#state_error').parent().find('input').addClass('select_error');
                validRes = false;
            }else{
                $('#state_error').hide();
                $('#state_error').parent().find('input').removeClass('select_error');
            }
            if(!validRes){return false;}


            data.field.id = param_id;
            facade.ajax({url: ask_engin_kaijun, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    dataPostTimeOut();
                }
            });

            return false;
        });

    });




</script>
</body>
</html>
